package com.paopao.domain;

import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * 数据库里的时间查出来是2011-11-1 22:55:13.0，而前端不需要毫秒值，所以自定义typehandler解决
 * @author SunLonghui
 *
 */
public class CalendarTypeHandler extends BaseTypeHandler<String>{

	@Override
	public String getNullableResult(ResultSet rs, String value)
			throws SQLException {
		// TODO Auto-generated method stub
		return getString(rs.getString(value));  
	}

	@Override
	public String getNullableResult(ResultSet rs, int arg1)
			throws SQLException {
		// TODO Auto-generated method stub
		  return this.getString(rs.getString(arg1));  
	}

	@Override
	public String getNullableResult(CallableStatement cs, int arg1)
			throws SQLException {
		// TODO Auto-generated method stub
		  return this.getString(cs.getString(arg1));
	}

	@Override
	public void setNonNullParameter(PreparedStatement ps, int i,
			String str, JdbcType jdbcType) throws SQLException {
		
		// StringBuffer result = new StringBuffer();  

	       ps.setString(i,str); 
	}

    private String getString(String value) {  

        if (value == null)  
            return null; 
        return value.substring(0, 19);
     }  

 }  

